package com.ruoyi.web.controller.room;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cdtu.room.dto.CalendarDto;
import com.cdtu.room.vo.CalendarVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.cdtu.room.domain.Calendar;
import com.cdtu.room.service.ICalendarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日历Controller
 * 
 * @author ruoyi
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/room/calendar")
public class CalendarController extends BaseController
{
    @Autowired
    private ICalendarService calendarService;

    /**
     * 查询日历列表
     */
    @PreAuthorize("@ss.hasPermi('room:calendar:list')")
    @GetMapping("/list")
    public TableDataInfo list(Calendar calendar)
    {
        startPage();
        List<Calendar> list = calendarService.selectCalendarList(calendar);
        return getDataTable(list);
    }

    /**
     * 导出日历列表
     */
    @PreAuthorize("@ss.hasPermi('room:calendar:export')")
    @Log(title = "日历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Calendar calendar)
    {
        List<Calendar> list = calendarService.selectCalendarList(calendar);
        ExcelUtil<Calendar> util = new ExcelUtil<Calendar>(Calendar.class);
        util.exportExcel(response, list, "日历数据");
    }

    /**
     * 获取日历详细信息
     */
    @PreAuthorize("@ss.hasPermi('room:calendar:query')")
    @GetMapping(value = "/{calendarId}")
    public AjaxResult getInfo(@PathVariable("calendarId") Long calendarId)
    {
        return success(calendarService.selectCalendarByCalendarId(calendarId));
    }

    /**
     * 新增日历
     */
    @PreAuthorize("@ss.hasPermi('room:calendar:add')")
    @Log(title = "日历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Calendar calendar)
    {
        return toAjax(calendarService.insertCalendar(calendar));
    }

    /**
     * 修改日历
     */
    @PreAuthorize("@ss.hasPermi('room:calendar:edit')")
    @Log(title = "日历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Calendar calendar)
    {
        return toAjax(calendarService.updateCalendar(calendar));
    }

    /**
     * 删除日历
     */
    @PreAuthorize("@ss.hasPermi('room:calendar:remove')")
    @Log(title = "日历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{calendarIds}")
    public AjaxResult remove(@PathVariable Long[] calendarIds)
    {
        return toAjax(calendarService.deleteCalendarByCalendarIds(calendarIds));
    }

    /**
     * 查询日历列表
     */
    @PreAuthorize("@ss.hasPermi('room:calendar:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(CalendarVo calendarVo)
    {
        startPage();
        List<CalendarDto> list = calendarService.getCalendarList(calendarVo);
        return getDataTable(list);
    }
}
